<?php

/**

 * Created by PhpStorm.

 * User: Administrator

 * Date: 2018/3/29 0029

 * Time: 16:03

 */

namespace app\home\controller;

use think\Db;

class Star extends Base {

    public function about() {

        //轮播图
        $this->publicIndex();
        $data_fg = Db::name('connect')->where('sign="pc"')->find();
        $this->assign('data_fg', $data_fg);
        return $this->fetch();
    }

    public function index() {
        $this->publicIndex();
        $style_id = intval(input('param.style_id'));
        //查询出横屏风格
        $where_style['style_id'] = $style_id;
        $where_style['sign'] = "pc";
        $where_style['type'] = "2";
        $where_style['is_show'] = 1;
        $where_style['style_heng'] = "1";
        $where_style['is_del'] = 0;
        $data_style_row = Db::name('zp')->where($where_style)->order('sort desc,id desc')->limit(4)->select();
        $this->assign('data_style_row', $data_style_row);


        //查询出竖图风格
        $where_style_col['style_id'] = $style_id;
        $where_style_col['sign'] = "pc";
        $where_style_col['type'] = "2";
        $where_style_col['is_del'] = 0;
        $where_style_col['is_show'] = 1;
        $where_style_col['style_heng'] = "2";
        $data_style_col = Db::name('zp')->where($where_style_col)->order('sort desc,id desc')->paginate(8, false, ['query' => request()->param()]);
         $page_col = $data_style_col->render();
        $this->assign('page_col', $page_col);
        $this->assign('data_style_col', $data_style_col);

        $data_banner = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=35')->order('sort desc,id desc')->field('banner_img,out_link')->select();

        $this->assign('data_banner', $data_banner);

//            查询出风格banner



        if ($style_id === 29) {
            $data_bannerfont = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=60')->order('sort desc,id desc')->limit(4)->select();
            $this->assign('data_bannerfont1', $data_bannerfont);
            $data_div_img = "<img src='/static/home/img/style-1.jpg' alt=''>";
            $this->assign("data_div_img", $data_div_img);
        }
         else if ($style_id === 28) {
            $data_bannerfont = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=61')->order('sort desc,id desc')->limit(4)->select();
            $this->assign('data_bannerfont1', $data_bannerfont);
            $data_div_img = "<img src='/static/home/img/style-2.jpg' alt=''>";
            $this->assign("data_div_img", $data_div_img);
        }

        else if ($style_id === 27) {
            $data_bannerfont = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=62')->order('sort desc,id desc')->limit(4)->select();
            $this->assign('data_bannerfont1', $data_bannerfont);
            $data_div_img = "<img src='/static/home/img/style-3.jpg' alt=''>";
            $this->assign("data_div_img", $data_div_img);
        }

        else if ($style_id === 21) {
            $data_bannerfont = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=63')->order('sort desc,id desc')->limit(4)->select();
            $this->assign('data_bannerfont1', $data_bannerfont);
            $data_div_img = "<img src='/static/home/img/style-4.jpg' alt=''>";
            $this->assign("data_div_img", $data_div_img);
        }
        else{
            $data_bannerfont = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->limit(4)->select();
            $this->assign('data_bannerfont1', $data_bannerfont);
            $data_div_img = "<img src='/static/home/img/style-4.jpg' alt=''>";
            $this->assign("data_div_img", $data_div_img);
        }


//            
        //客片底部广告
        //客片
        $where = [
            'a.sign' => "pc",
            'a.style_id' => 31,
            'a.type' => "2"
        ];
        $data_kp = Db::name('zp')->alias('a')

//                ->join('worksclass w','a.class_id=w.class_id')
                ->where($where)
                ->order('a.sort desc,a.id desc')

//                ->field("*,CEIL(FROM_UNIXTIME(a.ps_time,'%d')/7) zhou,w.name,w.class_id")
                ->paginate(3, false, ['query' => request()->param()]);
 
        $page = $data_kp->render();

        $this->assign('page', $page);

        $this->assign('data_kp', $data_kp);

        $this->assign('data_seo', getColumnseo(2));


        $id = intval(input('param.id'));
        if (!empty($id)) {


            $ere = [
                'sign' => "pc",
                'style_id' => 31,
                'type' => "2",
                'id' => $id
            ];

            $data_fgyp = Db::name('zp')->where($ere)->select();
            $arr = array();
            foreach ($data_fgyp as $k => $v) {
                $arr = $data_fgyp[$k]['works_photo'];
            }
            $new_arr = explode(',', $arr);



            $works_pic = Db('works_pic')->where('pic_id', 'in', $new_arr)
                            ->field('works_pic,pic_id')->select();

            $this->assign('works_pic', $works_pic);
        } else {
            $works_pic = "";
            $this->assign('works_pic', $works_pic);
        }







        return $this->fetch();
    }

    //客片详情页

    public function details($id = 0, $nid = 0, $pid = 0) {
        $this->publicIndex();
        if (!empty($id)) {
            $where['id'] = $id;
            $where = [
                'a.sign' => "pc",
                'a.is_show' => 1,
                'a.is_del' => 0,
                'a.id' => $id
            ];
            $data_style = Db::name('zp')->alias('a')
                    ->where($where)
                    ->order('a.sort desc,a.id desc')
                    ->find();
            //$works_pic = Db('works_pic')->where('pic_id','in',$data_kp['works_photo'])->field('works_pic,pic_id')->select();

            Db::name('zp')->alias('a')
                    ->where('id', $id)
                    ->update(['click' => $data_style['click'] + 1]);

            $this->assign('data_style', $data_style);

            //查询出推荐
            $where_s["style_id"] = $data_style["style_id"];
            $where_s["style_heng"] = "1";
            $where_s["is_del"] = 0;
            $data_style_s = Db::name('zp')->alias('a')
                    ->where($where_s)
                    ->order('a.sort desc,a.id desc')->limit(4)
                    ->select();

            $this->assign('data_style_s', $data_style_s);
        }

        if (!empty($nid)) {

            $where = [
                'a.sign' => "pc",
                'a.is_del' => 0,
                'a.is_show' => 1,
            ];



            $data_next = Db::name('works')->alias('a')
                    ->where($where)
                    ->where('a.id', '>', $nid)
                    ->order('a.sort desc,a.id desc')
                    ->find();



            if ($data_next) {

                $data_kp = Db::name('works')->alias('a')
                        ->where($where)
                        ->where('a.id', $data_next['id'])
                        ->order('a.sort desc,a.id desc')
                        ->find();

                $works_pic = Db('works_pic')->where('pic_id', 'in', $data_kp['works_photo'])
                                ->field('works_pic,pic_id')->select();

                Db::name('works')
                        ->where('id', $data_kp['id'])
                        ->update(['click' => $data_kp['click'] + 1]);

                $this->assign('data_next', $data_next);

                $this->assign('works_pic', $works_pic);

                $this->assign('data_kp', $data_kp);
            } else {

                echo "<script>alert('没有下一篇了');history.back();</script>";
                die;
            }
        }

        if (!empty($pid)) {

            $where = [
                'a.sign' => "pc",
                'a.is_del' => 0,
                'a.is_show' => 1,
            ];

            $data_prev = Db::name('works')->alias('a')
                    ->where($where)
                    ->where('a.id', '<', $pid)
                    ->order('a.sort desc,a.id desc')
                    ->find();

            if ($data_prev) {

                $data_kp = Db::name('works')->alias('a')
                        ->where($where)
                        ->where('a.id', $data_prev['id'])
                        ->order('a.sort desc,a.id desc')
                        ->find();

                $works_pic = Db('works_pic')->where('pic_id', 'in', $data_kp['works_photo'])
                                ->field('works_pic,pic_id')->select();

                Db::name('works')
                        ->where('id', $data_kp['id'])
                        ->update(['click' => $data_kp['click'] + 1]);

                $this->assign('data_prev', $data_prev);

                $this->assign('works_pic', $works_pic);

                $this->assign('data_kp', $data_kp);
            } else {

                echo "<script>alert('没有下一篇了');history.back();</script>";
                die;
            }
        }

        //底部详情也广告

        $data_bannerfont = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=40')
                        ->order('sort desc,id desc')->field('banner_img,out_link')->find();

        $this->assign('data_bannerfont', $data_bannerfont);

        //推荐客片

        $where = [
            'a.sign' => "pc",
            'a.is_show' => 1,
            'a.is_del' => 0
        ];

        $data_kplist = Db::name('works')->alias('a')
                ->where($where)
                ->order('a.sort asc')
                ->paginate(12);

        $this->assign('data_kplist', $data_kplist);

        return $this->fetch();
    }

}
